<template>
  <div>
    <van-nav-bar
         left-arrow
        class="app-nav-bar"
        title="卫生检查录入"
        @click-left="$router.back()"
      />
      <el-form label-width="80px"  :model="form">
            <el-form-item label="检查日期:">
                <el-date-picker
                    v-model="currentDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                </el-date-picker>
                <!-- {{tableData.checkDate}} -->
            </el-form-item>
            <el-form-item label="宿舍栋号:">
                <el-select v-model="buildingNo" placeholder="请选择">
                        <el-option
                        v-for="item in buildingNoList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
            </el-form-item>
            <el-form-item label="楼层:">
                <el-select @change="onChange" v-model="storey" placeholder="请选择">
                        <el-option
                        v-for="item in storeyList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
            </el-form-item>
            <el-form-item label="宿舍号:">
                <el-select v-model="bdormitoryId" placeholder="请选择">
                        <el-option
                        v-for="item in bdormitory"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
            </el-form-item>
             <el-form-item label="卫生项:">
                <el-select v-model="classContent" multiple placeholder="请选择">
                        <el-option
                        v-for="item in classList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
            </el-form-item>
            <el-form-item label="描述信息:">
                <el-input
                    type="textarea"
                    :rows="2"
                    placeholder="请输入内容"
                    v-model="form.leaveReason">
                </el-input>
            </el-form-item>
            <el-button type="success" @click="onSubmit">提交</el-button>
        </el-form>
  </div>
</template>

<script>
import {Notify} from 'vant'
export default {
    name:'HygieneAdd',
    data(){
        return{
            minDate: new Date(2000, 0, 1),
            maxDate: new Date(2021, 10, 1),
            currentDate:'',
           form:{
               studentNo: '',
                classId: '',
                className: "",
                studentName: '',
                leaveType: '',
                leaveReason: ''
           },
           tableData:[],
            status:[],
            statusListShare:false,
            statusContent:"",
            classList:[],
            classListShare:false,
            classContent:[],
             bdormitoryId:null,
             buildingNo:'',
             storey:'',
              bdormitory:[],
             buildingNoList:[],
             storeyList:[]
        }
    },
     methods:{
        async onSubmit(){
            var {data:res} = await this.request({
                url:this.$location.addHygiene,
                method:'post',
                data:{
                    bdormitoryId: this.bdormitoryId,
                    bdormitoryOptions:this.bdormitory,
                    buildingNo:this.buildingNo,
                    buildingNoOptions:this.buildingNoList,
                    checkDate:this.currentDate,
                    createById:'2',
                    deductIds:this.classContent,
                    hygieneDeductOptions:this.classList,
                    remark:this.form.leaveReason,
                    storey:this.storey,
                    storeyOptions:this.storeyList
                }
            })
            if(res.status==200){
                 this.$toast.success(res.msg)
                 this.$router.push('/Hygiene');
            }
        },
        onSelect(item){
            this.classContent=item.name;
            this.form.classId=item.id
            this.classListShare = false;
        },
        async getClassListAll(){
            const {data:res} =await this.request({url:this.$location.getHyDeAll});
            res.data.forEach(item=>{
                this.classList.push({
                    id:item.id,
                    name:item.deductOption
                })
            })
        },
        async getBuilding(){
            const {data:res} =await this.request({url:this.$location.building});
            res.data.forEach(item=>{
                this.buildingNoList.push({
                    id:item.dictValue,
                    name:item.dictLabel
                })
            })
        },
        async getStorey(){
            const {data:res} =await this.request({url:this.$location.storey});
            res.data.forEach(item=>{
                this.storeyList.push({
                    id:item.dictValue,
                    name:item.dictLabel
                })
            })
        },
        async onChange(){
            if(this.buildingNo!='' && this.storey!=''){
                var {data:res} = await this.request({
                    url:this.$location.getBDormitoryListByCol,
                    params:{
                        buildingNo: this.buildingNo,
                        storey: this.storey
                    }
                })
                // this.bdormitory=res.data
                res.data.forEach(item=>{
                    this.bdormitory.push({
                        id:item.id,
                        name:item.dormitoryNo
                    })
                })
            }
        },
         async select(){
            var {data:res} =await this.request({
                url:this.$location.getHygieneById,
                params:{
                    id:this.$route.params.id
                }
            })
           this.tableData=res.data;
        }
    },
    created(){
        this.getBuilding();
        this.getStorey();
        this.select();
         this.getClassListAll()
    }
}
</script>

<style lang="less" scoped>
 /deep/ .app-nav-bar{
        background-color: #35d299;
        .van-nav-bar__title{
            color: #fff;
        }
        .van-icon{
            color: #fff;
        }
    }
    .van-cell::after {
    border-bottom:0
}
.el-textarea {
    width: 70%; 
}
</style>